<%if (session[:role]=="admin") %>
<h1>Listing posts</h1>
<table class="three" cellspacing="0">
  <tr>
    <th>Title</th>
    <th>Body</th>
    <th>Published</th>
  </tr>
<% @posts.each do |post| %>
  <tr>
    <td><%=h post.title %></td>
    <td><%=h post.body %></td>
    <td><%=h post.published %></td>
    <td><%= link_to 'Show', post %></td>
    <td><%= link_to 'Edit', edit_post_path(post) %></td>
    <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>
<% else  %>
  <% for post in @posts %>
  <% if post.published %>
<div class="node sticky">
        <h2 class="title"><%=h post.title %></h2>
        <span class="submitted">Submitted on <%=h post.created_at %>
        <span class="user_badges">
        </span> </span>
        <div class="content">
          <div style="margin: 1px 1px 5px; padding: 1px; background-color: rgb(255, 255, 255);">
            <div style="margin-left: 0pt; padding-left: 0px; margin-top: 0pt; margin-bottom: 0pt; padding-right: 5px; position: relative;">
              <div style="margin-top: 5px; margin-bottom: 5px;"> 
                  <%    if post.img != nil
                           @mugshots = Mugshot.find_all_by_filename(post.img)
                           i =0
                           for mugshot in @mugshots do
                             if i==0
                            %>
                              <div style="float: left;">
                              <%= link_to image_tag(mugshot.public_filename,:size => "150x120"), mugshot.public_filename %>
                              </div>
                                 
                  <%         i=i+1
                             end
                          end
                      end %>      
                 <div style="float: left; width: 180px; padding-left: 10px;">
                    <p><%=h post.intro %></p>
                    </div> <div style="clear: both;"></div> </div> </div> </div>
        
        </div>
	<div class="nlinks">»
          <ul class="links inline">
            <li class="blog_usernames_blog first">
              <%=
              if post.author
               "โพสโดย "+ post.author
              end
            %>
            </li>
            <li class="comment_comments">
                <%= link_to post.comments.length.to_s+"comments",
                 :action => "show",
                 :id => post %>
            </li>
            <li class="node_read_more last">
                  <%= link_to "อ่านทั้งหมด",
      :action => "show",
      :id => post %>
            </li>
         </ul>
        </div>
  </div>
  <% end %>
<% end %>
<% end %>
<br />
<%= link_to 'New post', new_post_path %>